#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import pymysql
import os
from dotenv import load_dotenv

load_dotenv()

def check_user_table_structure():
    """检查用户表结构"""
    try:
        connection = pymysql.connect(
            host='localhost',
            port=3306,
            user='flask_dev',
            password='dev123456',
            database='flask_local',
            charset='utf8mb4'
        )
        
        print("数据库连接成功！")
        
        with connection.cursor() as cursor:
            # 检查用户表结构
            print("\n用户表结构:")
            cursor.execute("DESCRIBE user")
            columns = cursor.fetchall()
            for column in columns:
                print(f"  {column[0]} - {column[1]} - {column[2]}")
            
            # 检查用户表数据
            print("\n用户表数据:")
            cursor.execute("SELECT * FROM user LIMIT 5")
            users = cursor.fetchall()
            print(f"  用户总数: {len(users)}")
            for user in users:
                print(f"    {user}")
            
            # 检查评估记录表结构
            print("\n评估记录表结构:")
            cursor.execute("DESCRIBE scale_assessment")
            columns = cursor.fetchall()
            for column in columns:
                print(f"  {column[0]} - {column[1]} - {column[2]}")
            
            # 检查评估记录数据
            print("\n评估记录数据:")
            cursor.execute("SELECT COUNT(*) FROM scale_assessment")
            count = cursor.fetchone()[0]
            print(f"  评估记录总数: {count}")
            
            if count > 0:
                cursor.execute("SELECT * FROM scale_assessment LIMIT 3")
                assessments = cursor.fetchall()
                for assessment in assessments:
                    print(f"    {assessment}")
            
    except Exception as e:
        print(f"数据库连接失败: {e}")
        return False
    
    finally:
        if 'connection' in locals():
            connection.close()
    
    return True

if __name__ == "__main__":
    print("开始检查用户表结构...")
    check_user_table_structure()




